import { DataSource } from 'typeorm';
import { OperationType } from './entities/operation-type.entity';

export async function seedOperationTypes(dataSource: DataSource) {
  const operationTypeRepository = dataSource.getRepository(OperationType);

  const operationTypes = [
    {
      name: '装配作业',
      description: '产品组装和零部件装配工作',
      isActive: true,
    },
    {
      name: '焊接作业',
      description: '金属焊接和相关操作',
      isActive: true,
    },
    {
      name: '喷涂作业',
      description: '表面喷涂和涂装工作',
      isActive: true,
    },
    {
      name: '质检检查',
      description: '产品质量检验和测试',
      isActive: true,
    },
    {
      name: '包装作业',
      description: '产品包装和装箱工作',
      isActive: true,
    },
    {
      name: '设备维护',
      description: '机器设备维护和保养',
      isActive: true,
    },
    {
      name: '物料搬运',
      description: '原材料和成品搬运',
      isActive: true,
    },
    {
      name: '清洁整理',
      description: '工作区域清洁和整理',
      isActive: true,
    },
  ];

  for (const operationTypeData of operationTypes) {
    const existing = await operationTypeRepository.findOne({
      where: { name: operationTypeData.name },
    });

    if (!existing) {
      const operationType = operationTypeRepository.create(operationTypeData);
      await operationTypeRepository.save(operationType);
      console.log(`已创建操作类型: ${operationTypeData.name}`);
    }
  }

  console.log('操作类型数据初始化完成');
}